Option Strict Off
Option Explicit On
Namespace BMLERP
	Friend Class frmPUR200
		Inherits System.Windows.Forms.Form
		Private Sub cmdExit_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdExit.Click
			Me.Close()
		End Sub

		Private Sub txtfrom_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtfrom.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then txtTo.Focus()

			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtTo_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtTo.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then CalculatePO()
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub
		Sub CalculatePO()
			Dim SQL As Object
			Dim sumBAmount, recPOL, sumAmount, txtOHPON As Object
			Dim recPOH As ADODB.Recordset
			recPOH = DBconn.Execute("Select * from POH where OHPON>='" & txtFrom.Text & "' and OHPON<='" & txtTo.Text & "'")
			Do While Not recPOH.EOF
				txtOHPON = recPOH.Fields("OHPON").Value
				recPOL = DBconn.Execute("SELECT PO.*,POL.* FROM POH RIGHT OUTER JOIN " & "POL ON POH.OHPON = POL.OLPON where OLPON='" & txtOHPON & "' AND OLSTT<>'6'")
				sumAmount = 0
				sumBAmount = 0
				Do While Not recPOL.EOF
					If recPOL!OLPER = "1" Then
						sumBAmount = sumBAmount + ((recPOL!OLODQ * recPOL!OLUMP) - (recPOL!OLODQ * recPOL!OLUMP * recPOL!OLPDC))
					Else
						sumBAmount = sumBAmount + ((recPOL!OLODW * recPOL!OLUMP) - (recPOL!OLODW * recPOL!OLUMP * recPOL!OLPDC))
					End If
					sumAmount = sumBAmount * recPOL!OHEXR
					recPOL.MoveNext()
				Loop
				SQL = "Update POH set OHTAM=" & sumAmount & ",OHBTA=" & sumBAmount & " where OHPON='" & txtOHPON & "'"
				recPOH.MoveNext()
			Loop
			recPOL.Close()
			recPOH.Close()
			Adodc1.ConnectionString = ConnectString
			Adodc1.ConnectionTimeout = 10
			Adodc1.CommandType = ADODB.CommandTypeEnum.adCmdText
			Adodc1.RecordSource = "SELECT POH.*,AVM.VMNME,RCM.CMNME FROM POH INNER JOIN" & " RCM ON POH.OHCNO = RCM.CMCNO INNER JOIN AVM ON POH.OHVDN = AVM.VMVDN"
			Adodc1.Refresh()
			'VB6_AddADODataBinding()
		End Sub

		Private Sub frmPUR200_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
			Adodc1.ConnectionString = ConnectString
			Adodc1.ConnectionTimeout = 10
			Adodc1.CommandType = ADODB.CommandTypeEnum.adCmdText
			Adodc1.RecordSource = "SELECT POH.*,AVM.VMNME,RCM.CMNME FROM POH INNER JOIN" & " RCM ON POH.OHCNO = RCM.CMCNO INNER JOIN AVM ON POH.OHVDN = AVM.VMVDN"
			Adodc1.Refresh()
			VB6_AddADODataBinding()
			grdPO.DataSource = ADOBind_Adodc1.DataSource
			'  ADOBind_Adodc1.UpdateControls()
			Dim myDataFields As String() = {"OHPON", "OHPOD", "OHPOT", "CMNME", "OHCPO", "VMNME", "OHCUR", "OHRQD", "OHEXR", "OHTAM", "OHBTA", "OHPOS"}
			Dim myDataCaptions As String() = {"PO No", "PO Date", "PO Type", "Customer", "Cust Type", "Vendor", "Cur Code", "Request Date", "Ex Rate", "PO Amount", "Base total", "Status"}
			setDataGridView(myDataCaptions, myDataFields, grdPO)
		End Sub
	End Class
End Namespace